package functions;

import main.ContingencyTable;

public class PhiCoefficientFunction extends GeneralFunction {

	public PhiCoefficientFunction(String name) {
		super(name);
	}

	@Override
	public double calculate(ContingencyTable t) {
		return (pXY(t) - pX(t) * pY(t)) / (Math.sqrt(pX(t) * (1 - pX(t)) * pY(t) * (1 - pY(t))));
	}
	
	private double pXY(ContingencyTable t) {
		return t.f11() / t.N();
	}
	
	private double pX(ContingencyTable t) {
		return t.f1p() / t.N();
	}
	
	private double pY(ContingencyTable t) {
		return t.fp1() / t.N();
	}

}
